<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /**
         * String
         */ 
        var str = '  hello world     '
        // var str = new String('hello world')

        // console.log(str.length)

        // console.log(str.charAt(2))
        // console.log(str.indexOf('o'))
        // console.log(str.lastIndexOf('o'))
        // console.log(str.toLowerCase())
        // console.log(str.toUpperCase())
        // console.log(str.substring(2,7))
        // console.log(str.replace('el', 'xxx'))
        // console.log(str.split(' '))
        // console.log(str.trim())


        /**
         * Data
         */ 
        var today = new Date()
        // var d = new Date(2008,8,18)
        // var d = new Date(12345353454)
        // console.log(today)

        var year = today.getFullYear()
        var month = today.getMonth() + 1
        var date = today.getDate()
        var hour = today.getHours()
        var minute = today.getMinutes()
        var second = today.getSeconds()
        var day = today.getDay()
        var weekday = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
        // console.log(today.getTime())

        // var currentTime = year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second + ' ' + weekday[day]
        // 使用反引号定义字符串，称为模板字符串
        var currentTime = `${year}-${month}-${day} ${hour}:${minute}:${second} ${weekday[day]}`

        // console.log(currentTime)

        /**
         * 为个位数为0????
         */


        /**
         * JSON
         */ 
        var user = {
            "id": 1001,
            "name": "tom",
            "age": 18,
            "gender": "male",
            "height": 190.4,
            "address": {
                "province": "江苏省",
                "city": "南京市",
                "street": "江宁路"
            }
        }
        // console.log(user)
        // console.log(user.name)
        // console.log(user.height)
        // console.log(user.address.city)

        // JSON对象数组
        var users = [
            {
                "id": 1,
                "username": "admin",
                "password": "123",
                "status": 0
            },
            {
                "id": 2,
                "username": "tom",
                "password": "123",
                "status": 0
            },
            {
                "id": 3,
                "username": "jack",
                "password": "111",
                "status": 1
            }
        ]
        // 循环遍历
        // for(var user of users){
        //     console.log(user.id, user.username, user.password)
        // }

        /**
         * JSON对象和字符串之间的相互转换
         */
        // 1.将JSON对象转换为JSON字符串
        console.log(user)
        console.log(typeof user)

        var s = JSON.stringify(user)
        console.log(s)
        console.log(typeof s)

        // 2.将JSON字符串转换为JSON对象
        var s1 = '{"id":1008,"name":"汤小洋","age":18,"gender":"male","height":190.4}'
        console.log(s1)
        console.log(typeof s1)

        var obj = JSON.parse(s1)
        console.log(obj)
        console.log(typeof obj)


        /**
         * 对象字面量
         */ 
        var stu = {
            id: 101,
            name: 'alice',
            age: 20,
            study: function(){
                console.log('正在学习。。。。')
            } 
        }
        console.log(stu.name)
        console.log(stu.age)
        stu.study()

    </script>
</head>
<body>
    
</body>
</html>